package snapex.core.mapper;

import static snapex.core.mapper.UserAuthorityDynamicSqlSupport.*;

import java.util.List;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.delete.DeleteDSL;
import org.mybatis.dynamic.sql.delete.MyBatis3DeleteModelAdapter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.render.RenderingStrategy;
import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter;
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
import org.mybatis.dynamic.sql.select.SelectDSL;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.MyBatis3UpdateModelAdapter;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import snapex.core.model.UserAuthority;

@Mapper
public interface UserAuthorityMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<UserAuthority> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="UserAuthorityResult", value = {
        @Result(column="uat_user", property="uatUser", jdbcType=JdbcType.VARCHAR),
        @Result(column="uat_type", property="uatType", jdbcType=JdbcType.VARCHAR),
        @Result(column="uat_lastmodtime", property="uatLastmodtime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<UserAuthority> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<Long>> countByExample() {
        return SelectDSL.selectWithMapper(this::count, SqlBuilder.count())
                .from(userAuthority);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default DeleteDSL<MyBatis3DeleteModelAdapter<Integer>> deleteByExample() {
        return DeleteDSL.deleteFromWithMapper(this::delete, userAuthority);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(UserAuthority record) {
        return insert(SqlBuilder.insert(record)
                .into(userAuthority)
                .map(uatUser).toProperty("uatUser")
                .map(uatType).toProperty("uatType")
                .map(uatLastmodtime).toProperty("uatLastmodtime")
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(UserAuthority record) {
        return insert(SqlBuilder.insert(record)
                .into(userAuthority)
                .map(uatUser).toPropertyWhenPresent("uatUser", record::getUatUser)
                .map(uatType).toPropertyWhenPresent("uatType", record::getUatType)
                .map(uatLastmodtime).toPropertyWhenPresent("uatLastmodtime", record::getUatLastmodtime)
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<UserAuthority>>> selectByExample() {
        return SelectDSL.selectWithMapper(this::selectMany, uatUser, uatType, uatLastmodtime)
                .from(userAuthority);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<UserAuthority>>> selectDistinctByExample() {
        return SelectDSL.selectDistinctWithMapper(this::selectMany, uatUser, uatType, uatLastmodtime)
                .from(userAuthority);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExample(UserAuthority record) {
        return UpdateDSL.updateWithMapper(this::update, userAuthority)
                .set(uatUser).equalTo(record::getUatUser)
                .set(uatType).equalTo(record::getUatType)
                .set(uatLastmodtime).equalTo(record::getUatLastmodtime);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExampleSelective(UserAuthority record) {
        return UpdateDSL.updateWithMapper(this::update, userAuthority)
                .set(uatUser).equalToWhenPresent(record::getUatUser)
                .set(uatType).equalToWhenPresent(record::getUatType)
                .set(uatLastmodtime).equalToWhenPresent(record::getUatLastmodtime);
    }
}